﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FbKPI.Model;
using FbKPI.Facade;
using System.Web.Script.Serialization;
using System.Collections.ObjectModel;
using System.Web.Script.Services;

namespace FBKPI.Serializer
{
    /// <summary>
    /// Summary description for KPIByIDSerializer
    /// </summary>
    public class KPIByIDSerializer : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string result = this.GetData();
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string GetData()
        {
            int KPIID = Convert.ToInt16(HttpContext.Current.Request.Params["KPI"]);

            KPI result = new KPI();
            KPIFacade pf = new KPIFacade();
            result = pf.GetKPIByID(KPIID);

            var Data = new
            {
                result
            };
            var JSONSerializer = new JavaScriptSerializer();
            return JSONSerializer.Serialize(Data);
        }
    }
}